package com.example.shiwuyouproject.ui.fragment

import android.annotation.SuppressLint
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.shiwuyouproject.adapter.ArticleAdapter
import com.example.shiwuyouproject.base.BaseVmFragment
import com.example.shiwuyouproject.bean.Article
import com.example.shiwuyouproject.databinding.FragmentCurriculumBinding
import com.example.shiwuyouproject.ui.modelview.CurriculumViewModel
import com.example.shiwuyouproject.view.GroupItemDecoration
import com.haibin.calendarview.Calendar
import com.haibin.calendarview.CalendarView.*
import java.util.*

class CurriculumFragment:BaseVmFragment<FragmentCurriculumBinding, CurriculumViewModel>(),OnCalendarSelectListener,
OnYearChangeListener{
    override fun viewModelClass(): Class<CurriculumViewModel> = CurriculumViewModel::class.java


    override fun getViewBinding(): FragmentCurriculumBinding {
     return FragmentCurriculumBinding.inflate(layoutInflater)
    }

    override fun initView() {
      binding?.titleBar?.tvBack?.visibility= View.GONE
        binding?.titleBar?.tvTitle?.text="工作台"
        binding?.tvDateTime?.text= binding?.calendarView?.curYear?.toString()!!+"年"+ binding?.calendarView?.curMonth?.toString()!!+"月"+ binding?.calendarView?.curDay?.toString()!!+"日"
    }

    override fun setListener() {
        binding?.calendarView?.setOnCalendarSelectListener(this)
        binding?.calendarView?.setOnYearChangeListener(this)
        binding?.tvCurrentDay?.setOnClickListener {
            binding?.calendarView?.scrollToCurrent()
        }
    }

    override fun initData() {
        binding?.recyclerView?.layoutManager = LinearLayoutManager(context)
        binding?.recyclerView?.addItemDecoration(GroupItemDecoration<String, Article>())
        binding?.recyclerView?.adapter = ArticleAdapter(context)
        binding?.recyclerView?.notifyDataSetChanged()

    }

    override fun onCalendarOutOfRange(calendar: Calendar?) {
    }

    @SuppressLint("SetTextI18n")
    override fun onCalendarSelect(calendar: Calendar?, isClick: Boolean) {
            binding?.tvDateTime?.text=calendar?.year?.toString()!!+"年"+calendar?.month?.toString()!!+"月"+calendar?.day?.toString()!!+"日"
    }

    override fun onYearChange(year: Int) {

    }
}